{% extends 'PHPDishWebBundle::layout.html.twig' %}


{% block title %} {{ thread.name }} {% endblock %}

{% block script %}
    <script type="text/javascript" src="{{ asset('build/js/topic.js') }}"></script>
{% endblock %}

{% block content %}
    <div class="container" role="main">
        <div class="row">
            <div class="col-md-9">
                <div class="panel panel-u thread-detail">
                    <div class="panel-heading">
                        <div class="media thread">
                            <div class="media-left media-middle">
                                {% set threadUrl = path('thread_view', {'slug': thread.slug}) %}
                                <a href="{{ threadUrl }}" class="avatar">
                                    <img src="{{ asset(thread.cover|default('avatar/user1.jpg'))|imagine_filter('middle_square') }}" class="media-object img-circle img-responsive"/>
                                </a>
                            </div>
                            <div class="media-body">
                                <div class="pull-right follow-panel" data-role="follow-thread" data-slug="{{ thread.slug }}">
                                    {% if is_granted('IS_AUTHENTICATED_REMEMBERED') and thread.isFollowedBy(app.user) %}
                                        <button class="btn btn-default" data-action="unfollow"><i class="if i-plus"></i> 已关注</button>
                                    {% else %}
                                        <button class="btn u-btn-outline-primary" data-action="follow"><i class="if i-plus"></i> 关注</button>
                                    {% endif %}
                                </div>
                                <h4 class="media-heading">
                                    <a class="name" href="{{ threadUrl }}">{{ thread.name }}</a>
                                    {% if is_granted('edit', thread) %}
                                        <a class="meta" href="{{ path('thread_edit', {'slug': thread.slug}) }}" title="编辑"><i class="if i-edit"></i> 编辑节点</a>
                                    {% endif %}
                                </h4>
                                <ul class="list-unstyled list-inline meta">
                                    <li>话题 {{ thread.topicCount|default(0) }}</li>
                                    <li>订阅 {{ thread.followerCount|default(0) }}</li>
                                </ul>
                                <div>{{ thread.description }}</div>
                            </div>
                        </div>
                    </div>
                    <ul class="list-unstyled list-inline tab-nav" data-pjax-container="list-container">
                        {% set tab = app.request.query.get('tab') %}
                        <li {% if not tab%}class="active"{% endif %}><a href="{{ path('thread_view', {'slug': thread.slug}) }}">看帖</a></li>
                        <li {% if tab == 'recommend' %}class="active"{% endif %}><a href="{{ path('thread_view', {'slug': thread.slug, 'tab': 'recommend'}) }}">推荐</a></li>
                    </ul>
                    <div id="list-container">
                        <div class="panel-body topic-list">
                            {% include 'PHPDishWebBundle:Topic:topic_list.html.twig' %}
                        </div>
                        {% if topics.haveToPaginate %}
                            <div class="panel-footer">
                                {% from 'PHPDishWebBundle:Macros:paginator.html.twig' import paginator %}
                                {{ paginator(topics) }}
                            </div>
                        {% endif %}
                    </div>
                </div>
            </div>
            <div class="col-md-3">
                {% include 'PHPDishWebBundle:User:user_plate.html.twig' %}
                {{ render(controller('PHPDishForumBundle:Topic:todayHotTopics')) }}
                {{ render(controller('PHPDishUserBundle:User:latestUsers', {'limit': 10})) }}
                {% include 'PHPDishWebBundle:Common:friend_community.html.twig' %}
            </div>
        </div>
    </div>
    <script type="text/javascript">
        window.threadId = '{{ thread.id }}';
    </script>
{% endblock %}